package com.zzx.boot.message;

import com.zzx.boot.emus.ChatTypes;
import com.zzx.boot.serializable.CustomSerializable;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.Data;

@Data
public abstract class Message {

    public String message;
    public String type;


    public abstract ChatTypes getType();

    /**
     * 发送消息
     */
    public abstract void send(ChannelHandlerContext ctx);

    /**
     * 将message转换成Text
     */
    public TextWebSocketFrame toText(Message message){
        return new TextWebSocketFrame(CustomSerializable.gson().toJson(message));
    }


}
